from django.db import models

# django中自带的用户模型
from django.contrib.auth.models import AbstractUser
from common.db import BaseModel


# Create your models here.

class User(AbstractUser, BaseModel):
    """ 用户模型 """
    mobile = models.CharField(verbose_name='手机号', default='', max_length=11)
    avatar = models.ImageField(verbose_name='用户头像', blank=True, null=True)

    class Meta:
        db_table = 'users'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name


class Addr(models.Model):
    """ 收货地址表 """
    user = models.ForeignKey('User', verbose_name='所属用户', on_delete=models.CASCADE)
    phone = models.CharField(verbose_name='手机号码', max_length=11)
    name = models.CharField(verbose_name='联系人', max_length=20)
    province = models.CharField(verbose_name='省份', max_length=20)
    city = models.CharField(verbose_name='城市', max_length=20)
    county = models.CharField(verbose_name='县区', max_length=20)
    address = models.CharField(verbose_name='详细地址', max_length=200)
    is_default = models.BooleanField(verbose_name='是否默认地址', default=False)

    class Meta:
        db_table = 'addr'
        verbose_name = '收货地址表'
        verbose_name_plural = verbose_name


class Area(models.Model):
    """ 省市区地址模型 """
    name = models.CharField(verbose_name='地区名', max_length=20)  #
    pid = models.IntegerField(verbose_name='上级id')  #
    lever = models.CharField(verbose_name='区域等级', max_length=20)  #

    class Meta:
        db_table = 'area'
        verbose_name = '地区表'
        verbose_name_plural = verbose_name


class City(models.Model):
    """ 省市区地址模型 """
    name = models.CharField(verbose_name='地区名', max_length=20)  #
    parentid = models.IntegerField(verbose_name='上级id')  #
    shortname = models.CharField(verbose_name='简称', max_length=40)
    leveltype = models.CharField(verbose_name='区域等级', max_length=20)  #
    citycode = models.CharField(verbose_name='城市代码', max_length=7)
    zipcode = models.CharField(verbose_name='邮编', max_length=7)
    lng = models.CharField(verbose_name='经度', max_length=20)
    lat = models.CharField(verbose_name='纬度', max_length=20)
    pinyin = models.CharField(verbose_name='拼音', max_length=40)
    status = models.BooleanField(default=1)

    class Meta:
        db_table = 'city'
        verbose_name = '城市表'
        verbose_name_plural = verbose_name


class VerifCode(models.Model):
    """ 验证码表 """
    mobile = models.CharField(verbose_name='手机号', default='', max_length=11)
    code = models.CharField(verbose_name='验证码', max_length=6)
    create_time = models.DateTimeField(verbose_name='生成时间', auto_now_add=True)

    class Meta:
        db_table = 'verifcode'
        verbose_name = '手机验证码表'
        verbose_name_plural = verbose_name
